﻿using AspNetCoreRateLimit;
using Developer.Core.FrameWork.GlobalVar;
using Microsoft.AspNetCore.Builder;
using System;
using System.Collections.Generic;
using System.Text;

namespace Developer.Core.FrameWork.IPLimit
{
    /// <summary>
    /// IP限流中间件
    /// </summary>
    public static class IPLimitMiddleWare
    {
        /// <summary>
        /// 使用时尽量放在所有中间件的最前面
        /// </summary>
        /// <param name="app"></param>
        public static void UseIPLimit(this IApplicationBuilder app)
        {
            if (app == null)
                throw new ArgumentNullException(nameof(app));

            // 是否开启IP限流
            if (GlobalVars.IsIPLimit)
                app.UseIpRateLimiting();
        }
    }
}
